package book.useraction;

import book.status.Status;
import book.userentity.User;
import book.userservice.UserService;
import com.nf.Annotation.Autowired;
import util.HttpFactory;
import view.exten.ChongDingXiangView;
import view.exten.JsonView;

public class UserHandler {
    @Autowired("UserServiceImpl")
    private UserService userService;
    /**
     * @see :通过一个User对象来注册用户
     */
    public boolean insertUser(User user) {
        boolean i = userService.insertUser(user);
        return i;
    }
    /**
     * @see :通过手机号查询出用户 判断是否登录成功
     * 返回值为： 账号错误 密码错误
     */
    public void judgeLogin(String userPhone,String userPassword){
        User user = new User();
        user.setUserPhone(userPhone);
        user.setUserPassword(userPassword);
        String s = userService.judgeLogin(user);
        if(s.equals("")){
            HttpFactory.getActionFaction().getRequest().getServletContext().setAttribute("user",user);
        }
        /*if(s.equals("登录成功")){
            HttpFactory.getActionFaction().getRequest().getServletContext().setAttribute("user",user);
            new ChongDingXiangView("bookselectAllBook");
        }else{
            new JsonView(s);
        }*/
        new JsonView(s);
    }
}
